package blackhouse_dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import blackhouse_entity.subject;

public class subject_dao extends jdbc_dao
{
	public List<subject> show_subject(String sql) throws SQLException
	{
		List<subject> list = new ArrayList<subject>();
		ResultSet RS = query(sql);
		while (RS.next())
		{
			subject sub = new subject();
			sub.setId(RS.getInt("id"));
			sub.setSubjectcode(RS.getInt("subjectCode"));
			sub.setSubjectname(RS.getString("subjectName"));
			sub.setTeacher(RS.getString("tName"));
			sub.setGradeName(RS.getString("gradeName"));
			list.add(sub);
		}
		close(conn, st, RS);
		return list;
	}

	public List<subject> cheek_subject(String sql) throws SQLException
	{
		List<subject> list = new ArrayList<subject>();
		ResultSet RS = query(sql);
		while (RS.next())
		{
			subject sub = new subject();
			sub.setId(RS.getInt("id"));
			sub.setSubjectname(RS.getString("subjectName"));
			list.add(sub);
		}
		close(conn, st, RS);
		return list;
	}

	public int showgradeID(String sql) throws SQLException
	{
		ResultSet RS = query(sql);
		int ID = 0;
		while (RS.next())
		{
			ID = RS.getInt("gradeID");
		}
		return ID;
	}

	public List<subject> show_subgrade(String sql) throws SQLException
	{
		List<subject> list = new ArrayList<subject>();
		ResultSet RS = query(sql);
		while (RS.next())
		{
			subject sub = new subject();
			sub.setId(RS.getInt("id"));
			sub.setSubjectcode(RS.getInt("subjectCode"));
			sub.setSubjectname(RS.getString("subjectName"));
			sub.setTeacher(RS.getString("teacherName"));
			sub.setCreateTime(RS.getString("createTime"));
			sub.setGradeName(RS.getString("gradeName"));
			list.add(sub);
		}
		close(conn, st, RS);
		return list;
	}

	public boolean delsubject(String sql)
	{
		return update(sql) > 0;
	}
}
